package com.breeze.blockchain.controller.admin.form.file;

import static com.breeze.components.oss.mybaits.entity.table.FileDetailTable.FILE_DETAIL;

import com.breeze.components.mybatis.page.AbstractPageQuery;
import com.breeze.components.oss.mybaits.entity.FileDetailDo;
import com.mybatisflex.core.query.If;
import com.mybatisflex.core.query.QueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * @author breeze
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Schema
public class FileDetailPageForm extends AbstractPageQuery<FileDetailDo> {

  @Schema(title = "文件名称")
  String filename;

  @Schema(title = "文件url")
  String url;

  @Schema(title = "原始文件名称")
  String originalFilename;

  @Override
  public QueryWrapper toQueryWrapper() {
    return super.toQueryWrapper()
        .where(
            FILE_DETAIL
                .FILENAME
                .like(getFilename(), If::hasText)
                .and(FILE_DETAIL.URL.like(getFilename(), If::hasText))
                .and(FILE_DETAIL.ORIGINAL_FILENAME.like(getOriginalFilename(), If::hasText)))
        .orderBy(FILE_DETAIL.ID.desc());
  }
}
